<script src="<{$base_url}>/app/desktop/statics/js/moo.js" type="text/javascript"></script>
<!--<script src="http://wiki.zx.shopex.cn/demos/source/switchable.js"></script>-->
<script src="<{$base_url}>/app/site/statics/js/coms/switchable.js" type="text/javascript"></script>

<div id="member-main" class="member-main">
    <h1 class="title"><{t}>确认收货<{/t}></h1>
    <form action="<{link app=business ctl=site_order act=gofinish}>" enctype="multipart/form-data" encoding="multipart/form-data" method="post" name="return_save" id='x-return-form'>
    <ul class="je_ac_limtime" id="timecount">
     <li><strong>距离自动确认收货还有：</strong></li>
     <li><a href="#" class="day">00</a>天</li>
     <li><a href="#" class="hour">00</a>小时</li>
     <li><a href="#" class="minute">00</a>分</li>
     <li><a href="#" class="second">00</a>秒</li>
     <div class="cl_zhi"></div>
    </ul>
    <input type="hidden" name="order_id" value="<{$order_id}>">
	<input id="agree" type="submit" value="确认收货">
</form>
</div>

<script>
    (function() {
        var timestamp_statues = (new Date()).valueOf();
        var timeCount=timestamp_statues;
        var timeCount = this.timeCount = {
            init:function(nowtime,endtime,dom){
                var diff = Math.abs((nowtime.getTime() - endtime.getTime())/1000);
                var secondDiff = diff % 60;
                var minuteDiff = ((diff - secondDiff)/60) % 60;
                var hourDiff = ((diff - secondDiff  - minuteDiff*60)/3600) % 24;
                var dayDiff = (diff - secondDiff  - minuteDiff*60 - hourDiff*3600) / 86400;
                var timeDiff = [dayDiff,hourDiff,minuteDiff,secondDiff];
                this.s = (function(){this.calcTime.periodical(1000,this,{
                        time:timeDiff,
                        dom:dom
                    })}).delay(100,this);
            },
            addZero:function(timeDiff){
                for(var i=0;i<timeDiff.length;i++){
                    if(timeDiff[i].toString().length<2){
                        timeDiff[i] = "0" + timeDiff[i].toString();
                        return timeDiff;
                    }
                }
            },
            formatToInt : function(timeDiff){
                for(var i=0;i<timeDiff.length;i++){
                    parseInt(timeDiff[i]);
                };
                return timeDiff;
            },
            judgeTime : function(timeDiff){
                if(timeDiff[3]< 0  && timeDiff[2]>0){
                    timeDiff[3] = 59;
                    timeDiff[2]--;
                    return timeDiff;
                }else if(timeDiff[3] <0 && timeDiff[2]==0 && timeDiff[1]>0){
                    timeDiff[3] = 59
                    timeDiff[2] = 59;
                    timeDiff[1]--;
                    return timeDiff;
                }else if(timeDiff[3] <0 && timeDiff[2]==0 && timeDiff[1]==0 && timeDiff[0]>0){
                    timeDiff[3] = 59
                    timeDiff[2] = 59;
                    timeDiff[1] = 23;
                    timeDiff[0]--;
                    return timeDiff;
                }else if(timeDiff[3]==0 && timeDiff[2]==0 && timeDiff[1]==0 && timeDiff[0]==0){
                    $clear(this.s);
                    $('timecount').innerHTML='<p>自动确认收货！</p>';
                    $('scarebuyingprice').display='none';
                    $('scarebuyingsucc').display='';
                    return;
                }
            },
            calcTime : function (obj){
                if(!obj.dom) return;
                var _timeDiff = obj.time;
                this.addZero(_timeDiff);
                this.formatToInt(_timeDiff);
                _timeDiff[3]--;
                this.judgeTime(_timeDiff);
                this.addZero(_timeDiff);
                var dom = obj.dom;
                dom.second.innerHTML = _timeDiff[3];
                dom.minute.innerHTML = _timeDiff[2];
                dom.hour.innerHTML = _timeDiff[1];
                dom.day.innerHTML = _timeDiff[0];
            },
            calcDesc:function(){
                $clear(this.s);
                $('timecount').innerHTML='<p>自动确认收货！</p>';
                $('scarebuyingprice').display='none';
                $('scarebuyingsucc').display='';
                return;
            }
        }
    })();
    (function(){
        var timeNow;
        var timeEnd= new Date(<{$time}>);
        var dom = {
            second: $E('.second'),
            minute:$E('.minute'),
            hour:$E('.hour'),
            day:$E('.day')
        };
        new Request({
            url:'<{$scarebuyings_data.js_url}>',
            onComplete:function(re){
                timeNow=new Date(<{$now_time}>); 
                if(timeEnd.getTime() > timeNow.getTime()){
                    timeCount.init(timeEnd,timeNow,dom);
                }else{
                    new Request.HTML({
							url:'<{link app=business ctl=site_member act=js_function}>',
							method:'post',
							data:'order_id=<{$order_id}>',
					}).send();
                }
            }
        }).send();
    })();
 </script>